﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Verifications;

namespace Pixysoft.Framework.Reflection.Core
{
    class DummyParameterInfo : DummyMemberInfo, IDummyParameterInfo
    {
        int position = -1;
        IDummyType _value = null;

        public DummyParameterInfo(string name, int position)
        {
            this.Name = name;
            this.position = position;
        }

        public int Position
        {
            get { return position; }
        }

        [ParameterType]
        public IDummyType ParameterType
        {
            get { return _value; }
            set
            {
                //输入可能为null 在数据模式中，会出现null数据值 代表空

                _value = value;
            }
        }

        public IDummyParameterInfo CloneFrom(IDummyMethodInfo parent)
        {
            return parent.CreateParameter(this.Name, this.position);
        }

        public override bool Verify()
        {
            base.Verify();

            foreach (IDummyType att in GetCustomAttributes())
                att.Verify();

            return true;
        }

        public override void Dispose()
        {
            this._value = null;
            base.Dispose();
        }

        public override string ToString()
        {
            if (ParameterType == null)
                return Name;

            StringBuilder builder = new StringBuilder();
            builder.Append(ParameterType.ToString()).Append(" ").Append(Name);
            return builder.ToString();
        }

        internal class ParameterTypeAttribute : Attribute { }
    }
}
